# 打开百度搜索网站并且找到百度网站的搜索框，输入你要搜索的关键词《灌篮高手》
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
import time

browser = webdriver.Chrome()
browser.get("https://www.baidu.com/")
tag_class_name = "s_ipt"
# 定位到网站的搜索框
locator = (By.CLASS_NAME, tag_class_name)

#  解析网页，获取输入框，并且在输入框里输入：灌篮高手

# 强制等待10秒，如果没有返回就自动抛出异常
wait = WebDriverWait(browser, 10).until(EC.presence_of_element_located(locator))
# 获取到搜索框
input = browser.find_element_by_class_name(tag_class_name)
input.send_keys("灌篮高手")
# 模拟发送回车按钮进行搜索
input.send_keys(Keys.ENTER)
time.sleep(10)
browser.close()